home *** CD-ROM | disk | FTP | other *** search
/ MacFormat España 14 / MacFormat n. 14 (Spain) / MacFormat 14.bin / Shareware Internet / HyperCard / XCMD Docs / CompileIt! Source Code / dragRect(rect1,rect2,rect3,rect < prev    next >
Encoding:
Text File  |  1995-08-20  |  1.6 KB  |  47 lines

  1. global NewR:R,OldR:r,loc1:L,loc2:L
  2. function dragRect rect1,rect2,rect3,rect4
  3.   put thePort@.portRect.topleft.integerType[1] into portRect1
  4.   put thePort@.portRect.topleft.integerType[2] into portRec2
  5.   put thePort@.portRect.botRight.integerType[1] into portRect3
  6.   put thePort@.portRect.botRight.integerType[2] into portRect4
  7.   setRect oldR,rect1,rect2,rect3,rect4
  8.   put OpenPicture(oldR) into picHndl -- store a handle to the picture
  9.   copyBits thePort@.portbits,thePort@.portbits,oldr,oldr,0,NIL
  10.   closePicture
  11.   put rect3-rect1 into PicWidth
  12.   put rect4-rect2 into PicHeight
  13.   repeat while button()
  14.     put loc1 into loc2
  15.     GetMouse loc1
  16.     if loc1≠loc2 then
  17.       put loc1.integerType[2] into h
  18.       put loc1.integerType[1] into v
  19.       if WithinRect(h,v,portRect1,portRect2,portRect3,portRect4) then -- still in window
  20.         setrect newR,h,v,h+PicWidth,v+PicHeight
  21.         MoveRect picHndl
  22.         put newR.topLeft into oldR.topLeft -- need to do in 4 byte segments for Move.L
  23.         put newr.botRight into oldR.botright
  24.       end if
  25.     end if
  26.   end repeat
  27.   KillPicture pichndl
  28.   return newR.integerType[1] & "," & newR.integerType[2] & "," & newR.integerType[3] & "," & newR.integerType[4]
  29.   invalRect thePort@.portRect -- redraw window
  30. end dragRect
  31.  
  32. on MoveRect picHndl -- this does the actual move
  33.   eraseRect oldR
  34.   drawPicture picHndl,newR
  35. end MoveRect
  36.  
  37. function WithinRect h,v,r1,r2,r3,r4 -- this is the same as a within in HC
  38.   put h*1 into hh
  39.   put v*1 into vv
  40.   put r1*1 into rr1
  41.   put r2*1 into rr2
  42.   put r3*1 into rr3
  43.   put r4*1 into rr4
  44.   if (hh≥rr1 and vv≥rr2) and (hh≤rr3 and vv≤rr4) then return true
  45.   else return false
  46. end WithinRect
  47.